package org.singledog.form.builder.parser;

import org.singledog.form.builder.ComponentType;

import java.util.*;

/**
 * @author adam
 * @date 2019/5/1
 */
public class ComponentParserRegistry {

	private static Map<ComponentType, ComponentParser> parserMap;

	static {
		Map<ComponentType, ComponentParser> map = new HashMap<>();
		ServiceLoader<ComponentParser> serviceLoader = ServiceLoader.load(ComponentParser.class);
		for (ComponentParser parser : serviceLoader) {
			map.put(parser.supportType(), parser);
		}

		parserMap = Collections.unmodifiableMap(map);
	}

	public static ComponentParser getComponentParser(ComponentType componentType) {
		return parserMap.get(componentType);
	}

}
